new Vue({
	el:"#app",
	data:{
		uid:0,
		allVideoNum:100,
		videoList:[],
		typeList:[],
		auditStatusList:[],
		stayReleaseNum:0,
		passReleaseNum:0,
		notPassReleaseNum:0
	},
	methods:{
		sort(){
			var sortType=$("#sortChoose").val()
			axios.post(API+'sortMyRelease',{
				"list":this.videoList,
				"sortType":sortType
			}).then(response => {
				this.videoList=response.data
			}).catch(error => {
				console.error(error);
			});
		},
		changeList(){
			var classify=$("#classifyChoose").val()
			axios.post(API+'sortByClassify',{
				"userId":this.uid,
				"classId":classify,
			}).then(response => {
				this.videoList=response.data
				this.auditStatusList=this.videoList
				this.auditStatusNum()
			}).catch(error => {
				console.error(error);
			});
		},
		auditStatus(e){
			var auditType = e.currentTarget.innerHTML.substring(0,3);
			this.videoList=this.auditStatusList
			if(auditType=="进行中"){
				this.videoList = this.videoList.filter(function(data){
					return data.auditStatus === 0
				})
			}else if(auditType=="已通过"){
				this.videoList = this.videoList.filter(function(data){
					return data.auditStatus === 1
				})
			}else{
				this.videoList = this.videoList.filter(function(data){
					return data.auditStatus === 2
				})
			}
		},
		auditStatusNum(){
			//返回待审核数
			this.stayReleaseNum = this.videoList.filter(function(data){
				return data.auditStatus === 0
			}).length
			//返回已经通过数量
			this.passReleaseNum = this.videoList.filter(function(data){
				return data.auditStatus === 1
			}).length
			//返回未通过数量
			this.notPassReleaseNum = this.videoList.filter(function(data){
				return data.auditStatus === 2
			}).length
		}
	},
	mounted() {
		this.uid=localStorage.getItem("userid")
		//查询我的作品数量
		axios.get(API+'selMyRelease?userId='+this.uid).then(response => {
			this.allVideoNum = response.data.length
			this.videoList=response.data
			this.auditStatusList=this.videoList
			this.auditStatusNum()
		}).catch(error => {
			console.error(error);
		});
		
		//查询分类
		axios.get(API+'myClassifyNum?userId='+this.uid).then(response => {
			this.typeList=response.data
		}).catch(error => {
			console.error(error);
		});
	}
})

//jq部分
$(function() {
	var a = document.getElementsByName("vedioBox")
	for (let i = 0; i < a.length; i++) {
		var video = document.getElementsByName("vedioBox")[i].firstElementChild;
		console.log("保险1："+video.duration)
		if (!isNaN(video.duration)) {
			setTime(video, i)
		} else {
			video.addEventListener('loadeddata', function() {
				console.log("保险2："+video.duration)
				if (!isNaN(video.duration)) {
					
					setTime(video, i)
				}
			});
		}
	}
})

function setTime(video, i) {
	var duration = Math.round(video.duration); // 获取视频时长（秒）
	//console.log('视频时长:', duration, '秒');
	var m = Math.floor(duration / 60)
	var s = duration - 60 * m
	if (Math.floor(s / 10) == 0) {
		document.getElementsByName("vedioBox")[i].firstElementChild.nextElementSibling.textContent = m + ":0" + s;
	} else {
		document.getElementsByName("vedioBox")[i].firstElementChild.nextElementSibling.textContent = m + ":" + s;
	}
}